package com.smart;

import com.smart.adapter.ChannelAdapterFactory;
import com.smart.adapter.impl.*;
import com.smart.enums.ChannelType;
import com.smart.service.ChannelService;

public class Main {
    public static void main(String[] args) {
        // 创建各渠道工厂
        ChannelAdapterFactory phoneFactory = new PhoneChannelAdapterFactory();
        ChannelAdapterFactory webFactory = new WebChannelAdapterFactory();
        ChannelAdapterFactory wechatFactory = new WeChatChannelAdapterFactory();

        // 测试电话渠道接入
        processChannel(phoneFactory, ChannelType.PHONE, "来电号码：13800138000");

        // 测试网页渠道接入
        processChannel(webFactory, ChannelType.WEB, "<script>alert(1)</script>用户咨询内容");

        // 测试微信渠道接入
        processChannel(wechatFactory, ChannelType.WECHAT, "{\"openid\":\"oZx9254\",\"content\":\"预约服务\"}");
    }

    private static void processChannel(ChannelAdapterFactory factory, ChannelType type, String payload) {
        ChannelService adapter = factory.createAdapter();
        String sessionId = adapter.createSession(type);
        String processed = adapter.processMessage(payload, type);
        
        System.out.println("[" + type + "] 会话ID: " + sessionId);
        System.out.println("处理结果: " + processed);
        
        adapter.closeSession(sessionId);
        System.out.println("----------\n");
    }
}